package com.atguigu.rabbitmq.one;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Consumer {

    //队列的名称
      public static String  QUENE_NAME="hello";

      //接受信息
      public static void main(String[] args) throws IOException, TimeoutException {

          //创建连接的工厂
          ConnectionFactory factory = new ConnectionFactory();

          factory.setHost("39.107.43.12");
          factory.setUsername("admin");
          factory.setPassword("admin");
          //创建连接
          Connection connection = factory.newConnection();
          //获取信道
          Channel channel = connection.createChannel();

          //声明 接受消息
          DeliverCallback deliverCallback=(consumerTag,message)->{
              System.out.println(new String(message.getBody()));
          };


          //取消消息是的回调
          CancelCallback cancelCallback=consumerTag->{
              System.out.println("消费被中断");
          };

          /**
           * 消费者消费信息
           *1.表示消费那个队列
           * 2.消费成功之后 是否自动应答ture自动应答 false手动应打 默认false
           * 3.消费未成功消费的回调
           * 4.消费者取消消费的回调
           *
           */
          channel.basicConsume(QUENE_NAME,true,deliverCallback,cancelCallback);


      }




}
